<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Owner extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'owner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text','car'
    ];
    
    //获取车辆信息-司机信息
    public function getCarAttr($value,$data){
        return \app\admin\model\Car::with(['car_brand','driver'])->where(['car.uid'=>$data['uid']])->select();
    }


    public function user()
    {
        return $this->belongsTo('User', 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getStatusList()
    {
        return [0 => '待审核', 1 => '已通过', 2 => '已拒绝'];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }




}
